﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using Gizmox.WebGUI.Common;
using Gizmox.WebGUI.Forms;

namespace VisualWebGuiApplication2
{
    [Serializable]
    public partial class InvoiceControlAccompanyStockAdd : Form
    {
        Accompanying_stocks selcted;
        GazOnDevEntities db;
        string CurrentAmount;
        public InvoiceControlAccompanyStockAdd()
        {
            InitializeComponent();
           db=new GazOnDevEntities();

               comboBox1.DataSource = GetAccompanying_stocks();
              
                
            
        }

          public  List<Accompanying_stocks> GetAccompanying_stocks()
            {
                List<Accompanying_stocks> _Accompanying_stocks = new List<Accompanying_stocks>();
               
               
                    var query = from p in db.Accompanying_stocks  select p;
                    _Accompanying_stocks = query.ToList<Accompanying_stocks>();
               
                return _Accompanying_stocks;
            }

        
            
     
         
          
            private void comboBox1_SelectedIndexChanged_1(object sender, EventArgs e)
            {
                if (this.comboBox1.SelectedValue != null)
                {

                     selcted = (Accompanying_stocks)this.comboBox1.SelectedValue;
                      CurrentAmount = selcted.Count;
                    /*MessageBox.Show(selcted.Title);
                    MessageBox.Show(selcted.Id.ToString());*/
                }
            }


        public string Amount
        {
            get
            {
                return textAmount.Text;
            }
            set
            {
                textAmount.Text = value;
            }
        }

        public string Note
        {
            get
            {
                return txtNote.Text;
            }
            set
            {
                txtNote.Text = value;
            }
        }

        public string  Title
        {
            get
            {
                return selcted.Title;
            }
            
        }
        public string tankSize
        {
            get;
            set;

        }
        public string _Type
        {
            get;
            set;

        }
        public string _Typeid
        {
            get;
            set;

        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (null != selcted)
            {
                double amounttodif = Convert.ToDouble(CurrentAmount);
                _Type = "stock";
                _Typeid = selcted.Id.ToString();
                if (!string.IsNullOrEmpty(selcted.Unit))
                {
                    Note += selcted.Unit;
                    
                }
            if(!string.IsNullOrEmpty(textAmount.Text))
            {
                selcted.Count = (amounttodif - Convert.ToDouble(textAmount.Text)).ToString();
                amounttodif = amounttodif - Convert.ToDouble(textAmount.Text);
                if (amounttodif < 0)
                {
                    MessageBox.Show("אין מספיק פריטי במלאי " + CurrentAmount);
                }
                else
                {
                    db.SaveChanges();
                    this.Close();

                }
            }
            }

        }

     

    

     

    }
}